package com.benshanyang.transformer;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.fragment.app.FragmentTransaction;
import androidx.viewpager.widget.ViewPager;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;

import com.yk.transformer.viewpager2.AlphaPageTransformer;
import com.yk.transformer.viewpager2.DepthPageTransformer;
import com.yk.transformer.viewpager2.RotateDownPageTransformer;
import com.yk.transformer.viewpager2.RotateUpPageTransformer;
import com.yk.transformer.viewpager2.RotateYTransformer;
import com.yk.transformer.viewpager2.ScaleInTransformer;
import com.yk.transformer.viewpager2.ZoomOutPageTransformer;

public class ViewPager2Fragment extends Fragment {

    private ViewPager2 viewPager2;

    private int mParam1 = 0;
    private String animName = "";
    private static final String ARG_PARAM1 = "param1";

    public static ViewPager2Fragment newInstance(int param1) {
        ViewPager2Fragment fragment = new ViewPager2Fragment();
        Bundle args = new Bundle();
        args.putInt(ARG_PARAM1, param1);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getInt(ARG_PARAM1);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_view_pager2, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        viewPager2 = view.findViewById(R.id.view_pager_2);
        animName = "AccordionTransformer";
        switch (mParam1) {
            case 0:
                //ScaleInTransformer
                animName = "ScaleInTransformer";
                viewPager2.setPageTransformer(new ScaleInTransformer());
                break;
            case 1:
                //AlphaPageTransformer
                animName = "AlphaPageTransformer";
                viewPager2.setPageTransformer(new AlphaPageTransformer());
                break;
            case 2:
                //DepthPageTransformer
                animName = "DepthPageTransformer";
                viewPager2.setPageTransformer(new DepthPageTransformer());
                break;
            case 3:
                //RotateDownPageTransformer
                animName = "RotateDownPageTransformer";
                viewPager2.setPageTransformer(new RotateDownPageTransformer());
                break;
            case 4:
                //RotateUpPageTransformer
                animName = "RotateUpPageTransformer";
                viewPager2.setPageTransformer(new RotateUpPageTransformer());
                break;
            case 5:
                //RotateYTransformer
                animName = "RotateYTransformer";
                viewPager2.setPageTransformer(new RotateYTransformer());
                break;
            case 6:
                //ZoomOutPageTransformer
                animName = "ZoomOutPageTransformer";
                viewPager2.setPageTransformer(new ZoomOutPageTransformer());
                break;
        }
        viewPager2.setAdapter(new FragmentStateAdapter(getActivity()) {
            @NonNull
            @Override
            public Fragment createFragment(int position) {
                Fragment fragment = TestFragment.newInstance(position, 1, animName);
                return fragment;
            }

            @Override
            public int getItemCount() {
                return 8;
            }
        });
    }
}